/*   1:    */ package org.intellij.plugins.relaxNG.compact.parser;
/*   2:    */ 
/*   3:    */

import com.intellij.lang.PsiBuilder;
import com.intellij.lang.PsiBuilder.Marker;
import com.intellij.psi.tree.IElementType;
import org.intellij.plugins.relaxNG.compact.RncElementTypes;
import org.intellij.plugins.relaxNG.compact.RncTokenTypes;

import java.util.Map;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */ 
/*  12:    */ public class PatternParsing
/*  13:    */   extends DeclarationParsing
/*  14:    */ {
/*  15: 36 */   protected static final Map<IElementType, IElementType> TOKEN_MAP = ;
/*  16:    */   private final NameClassParsing a;
/*  17:    */   
/*  18:    */   static
/*  19:    */   {
/*  20: 40 */     TOKEN_MAP.put(RncTokenTypes.COMMA, RncElementTypes.SEQUENCE);
/*  21: 41 */     TOKEN_MAP.put(RncTokenTypes.PIPE, RncElementTypes.CHOICE);
/*  22: 42 */     TOKEN_MAP.put(RncTokenTypes.AND, RncElementTypes.INTERLEAVE);
/*  23: 43 */     TOKEN_MAP.put(RncTokenTypes.STAR, RncElementTypes.ZERO_OR_MORE);
/*  24: 44 */     TOKEN_MAP.put(RncTokenTypes.PLUS, RncElementTypes.ONE_OR_MORE);
/*  25: 45 */     TOKEN_MAP.put(RncTokenTypes.QUEST, RncElementTypes.OPTIONAL);
/*  26:    */   }
/*  27:    */   
/*  28:    */   public PatternParsing(PsiBuilder paramPsiBuilder)
/*  29:    */   {
/*  30: 51 */     super(paramPsiBuilder);
/*  31: 52 */     this.a = new NameClassParsing(paramPsiBuilder);
/*  32:    */   }
/*  33:    */   
/*  34:    */   public void parse()
/*  35:    */   {
/*  36: 56 */     parseTopLevel();
/*  37:    */   }
/*  38:    */   
/*  39:    */   protected boolean parsePattern()
/*  40:    */   {
/*  41: 60 */     PsiBuilder.Marker localMarker = this.myBuilder.mark();
/*  42: 61 */     if (!h())
/*  43:    */     {
/*  44: 62 */       localMarker.drop();
/*  45: 63 */       return false;
/*  46:    */     }
/*  47: 66 */     while (RncTokenTypes.BINARY_OPS.contains(currentToken()))
/*  48:    */     {
/*  49:    */       IElementType localIElementType;
/*  50: 68 */       if (RncTokenTypes.BINARY_OPS.contains(localIElementType = currentToken()))
/*  51:    */       {
/*  52:    */         do
/*  53:    */         {
/*  54: 70 */           advance();
/*  55: 71 */           if (!h()) {
/*  56: 72 */             error("Pattern expected");
/*  57:    */           }
/*  58: 74 */         } while (currentToken() == localIElementType);
/*  59: 75 */         localMarker.done((IElementType)TOKEN_MAP.get(localIElementType));
/*  60: 76 */         localMarker = localMarker.precede();
/*  61:    */       }
/*  62:    */     }
/*  63: 79 */     localMarker.drop();
/*  64: 80 */     return true;
/*  65:    */   }
/*  66:    */   
/*  67:    */   private boolean h()
/*  68:    */   {
/*  69: 84 */     PsiBuilder.Marker localMarker = this.myBuilder.mark();
/*  70: 85 */     if (!i())
/*  71:    */     {
/*  72: 86 */       localMarker.drop();
/*  73: 87 */       return false;
/*  74:    */     }
/*  75: 90 */     IElementType localIElementType = currentToken();
/*  76: 91 */     if (matches(RncTokenTypes.QUANTIFIER_OPS)) {
/*  77: 92 */       localMarker.done((IElementType)TOKEN_MAP.get(localIElementType));
/*  78:    */     } else {
/*  79: 94 */       localMarker.drop();
/*  80:    */     }
/*  81: 96 */     return true;
/*  82:    */   }
/*  83:    */   
/*  84:    */   private boolean i()
/*  85:    */   {
/*  86:100 */     PsiBuilder.Marker localMarker = this.myBuilder.mark();
/*  87:101 */     if (matches(ATTR_OR_ELEMENT))
/*  88:    */     {
/*  89:102 */       if (!this.a.parseNameClass())
/*  90:    */       {
/*  91:103 */         error("Name class expected");
/*  92:104 */         localMarker.drop();
/*  93:105 */         return false;
/*  94:    */       }
/*  95:107 */       k();
/*  96:108 */       localMarker.done(RncElementTypes.PATTERN);
/*  97:    */     }
/*  98:109 */     else if (matches(RncTokenTypes.KEYWORD_LIST))
/*  99:    */     {
/* 100:110 */       k();
/* 101:111 */       localMarker.done(RncElementTypes.LIST_PATTERN);
/* 102:    */     }
/* 103:112 */     else if (matches(RncTokenTypes.KEYWORD_MIXED))
/* 104:    */     {
/* 105:113 */       k();
/* 106:114 */       localMarker.done(RncElementTypes.MIXED_PATTERN);
/* 107:    */     }
/* 108:115 */     else if (matches(RncTokenTypes.KEYWORD_EXTERNAL))
/* 109:    */     {
/* 110:116 */       parseAnyUriLiteral();
/* 111:117 */       parseInherit();
/* 112:118 */       localMarker.done(RncElementTypes.EXTERNAL_REF);
/* 113:    */     }
/* 114:119 */     else if (matches(RncTokenTypes.KEYWORD_NOT_ALLOWED))
/* 115:    */     {
/* 116:120 */       localMarker.done(RncElementTypes.NOT_ALLOWED_PATTERN);
/* 117:    */     }
/* 118:121 */     else if (matches(RncTokenTypes.KEYWORD_TEXT))
/* 119:    */     {
/* 120:122 */       localMarker.done(RncElementTypes.TEXT_PATTERN);
/* 121:    */     }
/* 122:123 */     else if (matches(RncTokenTypes.KEYWORD_EMPTY))
/* 123:    */     {
/* 124:124 */       localMarker.done(RncElementTypes.EMPTY_PATTERN);
/* 125:    */     }
/* 126:125 */     else if (matches(RncTokenTypes.KEYWORD_PARENT))
/* 127:    */     {
/* 128:126 */       match(RncTokenTypes.IDENTIFIERS, "Identifier expected");
/* 129:127 */       localMarker.done(RncElementTypes.PARENT_REF);
/* 130:    */     }
/* 131:128 */     else if (matches(RncTokenTypes.KEYWORD_GRAMMAR))
/* 132:    */     {
/* 133:129 */       parseBracedGrammarContents();
/* 134:130 */       localMarker.done(RncElementTypes.GRAMMAR_PATTERN);
/* 135:    */     }
/* 136:131 */     else if (matches(RncTokenTypes.LPAREN))
/* 137:    */     {
/* 138:132 */       if (!parsePattern()) {
/* 139:133 */         error("Pattern expected");
/* 140:    */       }
/* 141:135 */       match(RncTokenTypes.RPAREN, "')' expected");
/* 142:136 */       localMarker.done(RncElementTypes.GROUP_PATTERN);
/* 143:    */     }
/* 144:137 */     else if (matches(RncTokenTypes.IDENTIFIERS))
/* 145:    */     {
/* 146:138 */       localMarker.done(RncElementTypes.REF_PATTERN);
/* 147:    */     }
/* 148:139 */     else if (matches(LA_DATATYPE))
/* 149:    */     {
/* 150:140 */       j();
/* 151:141 */       localMarker.done(RncElementTypes.DATATYPE_PATTERN);
/* 152:    */     }
/* 153:142 */     else if (currentToken() == RncTokenTypes.PREFIXED_NAME)
/* 154:    */     {
/* 155:143 */       makeName();
/* 156:144 */       j();
/* 157:145 */       localMarker.done(RncElementTypes.DATATYPE_PATTERN);
/* 158:    */     }
/* 159:146 */     else if (matches(RncTokenTypes.LITERAL))
/* 160:    */     {
/* 161:147 */       localMarker.done(RncElementTypes.DATATYPE_PATTERN);
/* 162:    */     }
/* 163:    */     else
/* 164:    */     {
/* 165:149 */       localMarker.drop();
/* 166:150 */       return false;
/* 167:    */     }
/* 168:152 */     return true;
/* 169:    */   }
/* 170:    */   
/* 171:    */   private void j()
/* 172:    */   {
/* 173:156 */     if (currentToken() == RncTokenTypes.LITERAL)
/* 174:    */     {
/* 175:157 */       advance();
/* 176:    */     }
/* 177:158 */     else if (matches(RncTokenTypes.LBRACE))
/* 178:    */     {
/* 179:159 */       l();
/* 180:160 */       if ((matches(RncTokenTypes.MINUS)) && 
/* 181:161 */         (!parsePattern())) {
/* 182:162 */         error("Pattern expected");
/* 183:    */       }
/* 184:165 */       match(RncTokenTypes.RBRACE, "'}' expected");
/* 185:    */     }
/* 186:    */   }
/* 187:    */   
/* 188:    */   private void k()
/* 189:    */   {
/* 190:170 */     match(RncTokenTypes.LBRACE, "'{' expected");
/* 191:171 */     if (!parsePattern()) {
/* 192:172 */       error("Pattern expected");
/* 193:    */     }
/* 194:174 */     match(RncTokenTypes.RBRACE, "'}' expected");
/* 195:    */   }
/* 196:    */   
/* 197:    */   private void l()
/* 198:    */   {
/* 199:178 */     IElementType localIElementType = currentToken();
/* 200:179 */     if (localIElementType != RncTokenTypes.RBRACE) {
/* 201:    */       do
/* 202:    */       {
/* 203:181 */         PsiBuilder.Marker localMarker = this.myBuilder.mark();
/* 204:182 */         match(RncTokenTypes.IDENTIFIER_OR_KEYWORD, "Identifier expected");
/* 205:183 */         match(RncTokenTypes.EQ, "'=' expected");
/* 206:184 */         match(RncTokenTypes.LITERAL, "Literal expected");
/* 207:185 */         localMarker.done(RncElementTypes.PARAM);
/* 208:186 */       } while (RncTokenTypes.IDENTIFIER_OR_KEYWORD.contains(currentToken()));
/* 209:    */     }
/* 210:    */   }
/* 211:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.intellij.plugins.relaxNG.compact.parser.PatternParsing

 * JD-Core Version:    0.7.0.1

 */